#Region "Comment"

'  Module                       :    Common
'  Purpose                      :    Defines the common functions.
'  Tables Referred              :    N/A
'  Tables Modified              :    N/A
'  Chronological Development
'Class                  Date            Contribution
'<Globals              4/18/07             Parminder> 

#End Region

Imports System.Data.SqlClient
Imports Crystal.CommonDBManagement.BLL
Imports System.Configuration
Imports System.Configuration.ConfigurationManager
Imports Infragistics.Win.DateTimeEditor
Imports Infragistics.Win.UltraWinGrid
Imports System.Text.RegularExpressions
Imports System.Runtime.CompilerServices
Imports Infragistics.Win
Imports System.Xml
Imports System.Windows.Forms.Form
Imports System.Windows.Forms
Imports System.Drawing

Public Module mdlCommon

#Region "Declare"
    'Master table-------------------------------------------------
    'Public frmmstTable As frmAddModifyRefTable = Nothing
    '-------------------------------------------------------------
#End Region

#Region "New Declare"

    'ID value for Select value that is used as first row in most of the drop downs
    Public m_strSelectIDValue As Integer = -1
    'ID value for Other value that is used as last row in most of the drop downs
    Public m_strOtherIDValue As Integer = -2

    'Public m_strNewIDValue = -3
    'Interger value that is passed to Stored Procedure to pick all records off the query
    Public m_strIntValueToPickAllRecords As Integer = -1
    'Text value for Select value that is used as first row in most of the drop downs
    Public m_strSelectTextValue As String = "---Select---"
    'Public m_strNewTextValue As String = "--New--"
    'Text value for Other value that is used as last row in most of the drop downs
    Public m_strOtherTextValue As String = "---Other---"
    Public m_strBlankTextValue As String = "---Blank---"
    Public m_strBlankIdValue As String = -6

    'Text value for Title value that is used as first row in title drop down
    Public m_strMsgBoxCaption As String = "Crystal"
#End Region

#Region "Enumerator" 'These are not subject to change, please update respctive tables in case of modifications
    Enum MessageBoxIcons
        Information = 1
        Warning = 2
        [Error] = 2
    End Enum

    ''' <summary>
    ''' This enumeration will find th ecriteria type.
    ''' </summary>
    ''' <remarks></remarks>
    Public Enum SearchCriteria
        BeginWith = 1
        Contains = 2
    End Enum

#End Region

#Region "General"

    Public Sub SetTabSettings(ByVal e As System.Windows.Forms.DrawItemEventArgs, ByVal Tab As System.Windows.Forms.TabControl)
        Dim g As Graphics = e.Graphics
        Dim tp As TabPage = Tab.TabPages(e.Index)
        Dim br As Brush
        Dim sf As New StringFormat
        Dim r As New RectangleF(e.Bounds.X, e.Bounds.Y + 2, e.Bounds.Width + 2, e.Bounds.Height - 2)
        sf.Alignment = StringAlignment.Center
        Dim strTitle As String = tp.Text
        'If the current index is the Selected Index, change the color
        If Tab.SelectedIndex = e.Index Then
            'this is the background color of the tabpage
            'you could make this a stndard color for the selected page
            'br = New SolidBrush(mdlCommon.GetFormBackColor)
            'this is the background color of the tab page
            g.FillRectangle(br, e.Bounds)
            'this is the background color of the tab page
            'you could make this a stndard color for the selected page
            'br = New SolidBrush(mdlCommon.GetLabelForeColor)
            g.DrawString(strTitle, Tab.Font, br, r, sf)
        Else
            'these are the standard colors for the unselected tab pages
            'br = New SolidBrush(mdlCommon.GetFormBackColor)
            g.FillRectangle(br, e.Bounds)
            ' br = New SolidBrush(mdlCommon.GetLabelForeColor)
            g.DrawString(strTitle, Tab.Font, br, r, sf)
        End If
    End Sub

    ''' <summary>
    ''' return Color schema
    ''' </summary>
    ''' <param name="Val"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetARGBDetails(ByVal Val As String) As Color

        Dim seperator() As String = {","}
        Dim colorschema() As String = Val.Split(seperator, StringSplitOptions.RemoveEmptyEntries)
        If (colorschema.Length = 4) Then
            If (IsNumeric(colorschema(0).ToString()) And IsNumeric(colorschema(1).ToString()) And IsNumeric(colorschema(2).ToString()) And IsNumeric(colorschema(3).ToString())) Then
                Return System.Drawing.Color.FromArgb(colorschema(0).ToString(), colorschema(1).ToString(), colorschema(2).ToString(), colorschema(3).ToString())
            Else
                Return Color.Empty
            End If
        Else
            Return Color.Empty
        End If

    End Function

    ''' <summary>
    ''' Dertermines whether to enable the teh proper button or not
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function EnableProper(ByVal SearchString As String) As Boolean
        Dim Seperator() As String = {" "}
        Dim str() As String = SearchString.Trim().Split(Seperator, System.StringSplitOptions.RemoveEmptyEntries)
        Dim Contains As Boolean = False
        Dim regex As New System.Text.RegularExpressions.Regex("^[A-Z]+$")
        For Each Val As String In str
            If (regex.IsMatch(Val)) Then
                Contains = True
                Return True
            End If
        Next
        Return False
    End Function

    ''' <summary>
    ''' converts to title case
    ''' </summary>
    ''' <param name="SearchString"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function AutoProperConversion(ByVal SearchString As String) As String
        Return StrConv(SearchString.ToString().Trim(), VbStrConv.ProperCase)
    End Function


    ''' <summary>
    ''' The following function is specifically for Map Investor and Map Fund in Fund and Investor Tab
    ''' </summary>
    ''' <param name="grid"></param>
    ''' <param name="GrdRow"></param>
    ''' <remarks></remarks>
    Public Sub SetExcelSearchedrecordOnTop(ByVal grid As UltraGrid, ByVal GrdRow As UltraGridRow)
        Dim col As RowScrollRegionsCollection = Nothing
        '***************************************************************************************
        'If the investor is not selected in the search, then no need to ammend the progressbar
        If (GrdRow Is Nothing) Then Exit Sub
        'Finished

        '***********************************************
        'The following code shall split the Grid and provide us that part in which we selected 
        'the investor excel record'
        col = grid.DisplayLayout.RowScrollRegions
        'Finished

        If (col Is Nothing) Then Exit Sub
        If (grid Is Nothing) Then Exit Sub
        If (grid.ActiveRow Is Nothing) Then Exit Sub
        Try
            'The following loop shall set the selected investor to top
            For i As Integer = 0 To grid.ActiveRow.Index - (col(0).ScrollPosition - 1) - 3
                col(0).Scroll(RowScrollAction.LineDown)
            Next
            'Finished
        Catch ex As Exception
            'MessageBox.Show(ex.Message)
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in SetExcelSearchedrecordOnTop in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
            MessageBox.Show(ex.Message, m_strMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try


    End Sub
    ' ''' <summary>
    ' ''' To show a message in Message Box
    ' ''' </summary>
    ' ''' <param name="strMessage">Message to be shown</param>
    ' ''' <remarks></remarks>
    'Public Sub ShowMessage(ByVal strMessage As String, ByVal messageboxicon As MessageBoxIcons)
    '    Select Case messageboxicon
    '        Case MessageBoxIcons.Information
    '            MessageBox.Show(strMessage, m_strMsgBoxCaption, MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Information)
    '        Case MessageBoxIcons.Warning
    '            MessageBox.Show(strMessage, m_strMsgBoxCaption, MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Warning)
    '        Case MessageBoxIcons.Error
    '            MessageBox.Show(strMessage, m_strMsgBoxCaption, MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Error)
    '    End Select
    'End Sub
#End Region

    Public Function checkdate(ByVal grid As Infragistics.Win.UltraWinGrid.UltraGrid, ByVal column_name As String, ByRef dateVal As String) As Boolean
        Dim str() As String
        Try
            If (grid.ActiveRow.Cells(column_name).EditorResolved.IsInEditMode) Then
                str = grid.ActiveRow.Cells(column_name).EditorResolved.CurrentEditText.ToString().Split("/")
                If (str.Length <> 3) Then
                    Return False
                End If
                If (Not IsNumeric(str(0)) Or Not IsNumeric(str(1)) Or Not IsNumeric(str(2))) Then
                    Return False
                End If
                If (Convert.ToInt16(str(0).ToString()) = 0 Or Convert.ToInt16(str(1).ToString()) Or Convert.ToInt16(str(2).ToString())) Then
                    Return False
                End If
                If (IsDate(grid.ActiveRow.Cells(column_name).EditorResolved.Value)) Then
                    dateVal = grid.ActiveRow.Cells(column_name).EditorResolved.Value
                    Return True
                Else
                    dateVal = ""
                    Return False
                End If
            Else
                If (IsDate(grid.ActiveRow.Cells(column_name).Value)) Then
                    dateVal = grid.ActiveRow.Cells(column_name).Value
                    Return True
                Else
                    dateVal = ""
                    Return False
                End If
            End If
            Return True
        Catch ex As Exception
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in checkdate in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
            Return False
        End Try

    End Function

    ''' <summary>
    ''' To check/uncheck permissions from Permission Grid
    ''' </summary>
    ''' <remarks></remarks>
    ''' 

    Public Sub CheckUncheckPermissions(ByRef ultraGridRow As UltraGrid, Optional ByRef IsChecked As Boolean = False)
        Try
            If CheckNothingUltraGridActiveCell(ultraGridRow) = False Then Exit Sub
            If ultraGridRow.ActiveCell Is Nothing Then Exit Sub
            If ultraGridRow.ActiveCell.Column.Header.Caption = "Category" OrElse ultraGridRow.ActiveCell.Column.Header.Caption = "Category Permissions" Then Exit Sub
            Dim IsAnyFalseChildrow As Boolean = False
            'ultraGridRow.ActiveRow.Index
            'ultraGridRow.DataSource
            'ultraGridRow.ActiveRow.Cells("Full").Text 
            IsChecked = True
            If ultraGridRow.ActiveRow.HasChild = False Then
                If ultraGridRow.ActiveRow.ParentRow IsNot Nothing Then
                    If ultraGridRow.ActiveRow.Cells(ultraGridRow.ActiveCell.Column.Header.Caption).Text = "True" Then
                        ultraGridRow.ActiveRow.ParentRow.Cells(ultraGridRow.ActiveCell.Column.Header.Caption).Value = "False"
                        'For Each dr As UltraGridRow In ultraGridRow.ActiveRow.ParentRow.ChildBands.Item(0).Rows
                        '    dr.Cells(ultraGridRow.ActiveCell.Column.Header.Caption).Value = "False"
                        'Next
                    Else
                        For Each dr As UltraGridRow In ultraGridRow.ActiveRow.ParentRow.ChildBands.Item(0).Rows
                            If dr.Index <> ultraGridRow.ActiveRow.Index Then
                                If dr.Cells(ultraGridRow.ActiveCell.Column.Header.Caption).Value = "False" Then
                                    IsAnyFalseChildrow = True
                                End If
                            End If
                        Next
                        If IsAnyFalseChildrow = False Then
                            ultraGridRow.ActiveRow.ParentRow.Cells(ultraGridRow.ActiveCell.Column.Header.Caption).Value = "True"
                        End If
                    End If
                End If
            End If
            If ultraGridRow.ActiveCell.Column.Header.Caption = "Select" Then
                If ultraGridRow.ActiveRow.Cells("Select").Text = "True" Then
                    ultraGridRow.ActiveRow.Cells("Select").Value = "False"
                    'ultraGridRow.ActiveRow.Cells("Select").Value = "False"
                    'ultraGridRow.ActiveRow.Cells("Modify").Value = "False"
                    ' ultraGridRow.ActiveRow.Cells("Delete").Value = "False"
                    ' ultraGridRow.ActiveRow.Cells("Visible").Value = "False"
                    If ultraGridRow.ActiveRow.HasChild Then
                        For Each dr As UltraGridRow In ultraGridRow.ActiveRow.ChildBands.Item(0).Rows
                            'dr.Cells("Full").Value = "False"
                            dr.Cells("Select").Value = "False"
                            'dr.Cells("Modify").Value = "False"
                            'dr.Cells("Delete").Value = "False"
                            'dr.Cells("Visible").Value = "False"
                        Next
                    End If
                Else
                    ultraGridRow.ActiveRow.Cells("Select").Value = "True"
                    'ultraGridRow.ActiveRow.Cells("Add").Value = "True"
                    'ultraGridRow.ActiveRow.Cells("Modify").Value = "True"
                    'ultraGridRow.ActiveRow.Cells("Delete").Value = "True"
                    'ultraGridRow.ActiveRow.Cells("Visible").Value = "True"
                    If ultraGridRow.ActiveRow.HasChild Then
                        For Each dr As UltraGridRow In ultraGridRow.ActiveRow.ChildBands.Item(0).Rows
                            'dr.Cells("Full").Value = "True"
                            dr.Cells("Select").Value = "True"
                            'dr.Cells("Modify").Value = "True"
                            'dr.Cells("Delete").Value = "True"
                            'dr.Cells("Visible").Value = "True"
                        Next
                    End If
                End If
            End If
            CType(ultraGridRow.DataSource, DataSet).AcceptChanges()
        Catch ex As Exception
            'MessageBox.Show(ex.Message)
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in CheckUncheckPermissions in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing

        End Try
    End Sub

#Region "UltraGrid"

    ''' <summary>
    ''' Check Active Row and Rows of Ultragrid for NOTHING
    ''' </summary>
    ''' <param name="grdUltraGrid"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>

    Public Function CheckNothingUltraGridActiveRow(ByVal grdUltraGrid As UltraGrid) As Boolean
        Try
            If grdUltraGrid.Rows Is Nothing Then Return False
            If grdUltraGrid.ActiveRow Is Nothing Then Return False
            Return True
        Catch ex As Exception
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in CheckNothingUltraGridActiveRow in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing

            Throw ex
        End Try
    End Function


    ''' <summary>
    ''' To Hide a column of a grid
    ''' </summary>
    ''' <param name="ultraGridRow">Grid Name</param>
    ''' <param name="columnName">Column to hide</param>
    ''' <remarks></remarks>
    Public Sub HideUltraGridColumn(ByRef ultraGridRow As UltraGrid, ByVal columnName As String)
        If ultraGridRow.Rows.Band.Columns.Exists(columnName) Then
            ultraGridRow.Rows.Band().Columns(columnName).Hidden = True
        End If
    End Sub

    ''' <summary>
    ''' To set width of a column
    ''' </summary>
    ''' <param name="ultraGrid"></param>
    ''' <param name="columnName"></param>
    ''' <param name="columnWidth"></param>
    ''' <remarks></remarks>
    Public Sub SetUltraGridColumnWidth(ByRef ultraGrid As UltraGrid, ByVal columnName As String, ByVal columnWidth As Integer)
        If ultraGrid.Rows.Band.Columns.Exists(columnName) Then
            ultraGrid.Rows.Band().Columns(columnName).Width = columnWidth
        End If
    End Sub

    Public Sub AddCheckboxColInUltraGrid(ByRef ultraGrid As UltraGrid, ByVal band As Integer, ByVal columnName As String, ByVal columnindex As Int16, ByVal columnWidth As Integer)
        Try
            If ultraGrid.DisplayLayout.Bands(band).Columns.Exists(columnName) Then Exit Sub
            ultraGrid.DisplayLayout.Bands(band).Columns.Insert(columnindex, columnName)
            ultraGrid.DisplayLayout.Bands(band).Columns(columnName).DataType = GetType(Boolean)
            ultraGrid.DisplayLayout.Bands(band).Columns(columnName).Style = Infragistics.Win.UltraWinGrid.ColumnStyle.CheckBox
            If columnWidth <> 0 Then
                ultraGrid.DisplayLayout.Bands(band).Columns(columnName).Width = columnWidth
            End If
        Catch ex As Exception
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in AddCheckboxColInUltraGrid in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
        End Try

    End Sub

#End Region

#Region "General"

    ''' <summary>
    '''  Validate Email Address
    ''' </summary>
    ''' <param name="lstrEmailAddress"> for validation purpose</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    ''' 
    Function EmailAddressCheck(ByVal lstrEmailAddress As String) As Boolean
        Try

            Dim lstrPattern As String = "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"
            Dim emailAddressMatch As Match = Regex.Match(lstrEmailAddress, lstrPattern)
            If emailAddressMatch.Success Then
                EmailAddressCheck = True
            Else
                MessageBox.Show("Please enter valid Email address.", m_strMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning)
                EmailAddressCheck = False
            End If
        Catch ex As Exception
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in EmailAddressCheck in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
        End Try
    End Function

#End Region

#Region "Functions"

    ' ''' <summary>
    ' ''' To check if text box is empty.
    ' ''' </summary>
    ' ''' <param name="strText"></param>
    ' ''' <returns></returns>
    ' ''' <remarks></remarks>

    'Public Function IsEmpty(ByVal strText As String) As Boolean
    '    If strText.Trim = "" Then
    '        Return True
    '    Else
    '        Return False
    '    End If
    'End Function

    Public Function intCalculatePriority(ByVal pstrPriority As String) As Integer
        Select Case pstrPriority
            Case "Normal"
                Return 0
            Case "Low"
                Return 1
            Case "High"
                Return 2
            Case Else
                Return 0
        End Select
    End Function

    ''' <summary>
    ''' Returns true if text in one text box is not equal to the other.
    ''' </summary>
    ''' <param name="strText1"></param>
    ''' <param name="strText2"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>

    Public Function IsSame(ByVal strText1 As String, ByVal strText2 As String) As Boolean
        If strText1.Trim <> strText2.Trim Then
            Return True
        Else
            Return False
        End If
    End Function

    ''' <summary>
    ''' To check if value is selected or not.
    ''' </summary>
    ''' <param name="cmbo"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>

    Public Function IsvalueSelected(ByVal cmbo As System.Windows.Forms.ComboBox) As Boolean
        If cmbo.SelectedIndex = -1 Or cmbo.SelectedValue = -1 Then
            Return True
        Else
            Return False
        End If
    End Function

    ''' <summary>
    ''' To check if Combo Text is Selected
    ''' </summary>
    ''' <param name="cmbo"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>

    Public Function IsComboTextSelected(ByVal cmbo As System.Windows.Forms.ComboBox) As Boolean
        If cmbo.SelectedIndex = -1 Or cmbo.SelectedValue = "0" Then
            Return True
        Else
            Return False
        End If
    End Function

    ''' <summary>
    ''' Function to set the format of Date
    ''' </summary>
    ''' <param name="DtCombo"></param>
    ''' <remarks></remarks>

    Public Sub SetDateFormat(ByVal DtCombo As Infragistics.Win.UltraWinEditors.UltraDateTimeEditor)
        'DtCombo.FormatString = BLLmdlCommon.DateFormat
        DtCombo.FormatString = Replace(BLLmdlCommon.DateFormat, "//", "/")
    End Sub

    Public Sub SetDateFormat(ByVal DtCombo As Windows.Forms.DateTimePicker)
        DtCombo.Format = DateTimePickerFormat.Custom
        DtCombo.CustomFormat = Replace(BLLmdlCommon.DateFormat, "//", "/")
    End Sub

    ''' <summary>
    ''' Function to get Total Fund Records.
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>

    Public Function TotalFundsRecords() As Integer
        'Dim loHistory As New Object
        'Dim dtTotalRecords As New DataTable
        'Dim lObjImportFndHistory As New cImportHistory
        'loHistory = lObjImportFndHistory.CountHistoryFundsRecords()
        'dtTotalRecords = CType(loHistory, DataSet).Tables(0)
        'If CheckNothingDataTable(dtTotalRecords) Then
        '    Return 0
        'Else
        '    Return dtTotalRecords.Rows(0).Item(0)
        'End If
    End Function

    ''' <summary>
    ''' This function checks whether the date is valid
    '''  It should check if the year is leap year and check if the date selected is
    '''  valid
    ''' </summary>
    ''' <param name="sDate"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>

    Private Function ValidateDate(ByVal sDate)
        Dim aMonth
        Dim aLeapMonth
        Dim aDateOfBirth
        Dim iDay, iMonth, iYear
        Dim Array As Array = Nothing
        ValidateDate = False
        Try
            'Days in month of a normal year
            aMonth = Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)

            'Days in month of a leap year
            aLeapMonth = Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)

            'Get the day, month and year
            aDateOfBirth = Split(sDate, "/")
            iDay = CInt(aDateOfBirth(0))
            iMonth = CInt(aDateOfBirth(1))
            iYear = CInt(aDateOfBirth(2))

            'If all the items - day, month, year are selected, do the validation....else return
            'Note : The month array starts from 0
            If (iDay <> 0) And (iMonth <> 0) And (iYear <> 0) Then
                If ((iYear Mod 4) = 0) Then
                    If (((iYear Mod 100) = 0) And ((iYear Mod 400) <> 0)) Then 'Normal year
                        'Check if the day entered is valid
                        If (iDay) <= aMonth(iMonth - 1) Then ValidateDate = True
                    Else 'Leap year
                        If (iDay) <= aLeapMonth(iMonth - 1) Then ValidateDate = True
                    End If
                Else 'Normal year
                    If (iDay) <= aMonth(iMonth - 1) Then ValidateDate = True
                End If
            End If

        Catch ex As Exception
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in ValidateDate in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
        End Try

    End Function

    Public Sub CountWinProcesses(ByRef parrWinProcesses As ArrayList)
        Try


            Dim WordProcesses() As Process
            Dim ProcessInfo As Diagnostics.Process
            Dim lhtWinProcesses As Hashtable
            WordProcesses = Process.GetProcessesByName("WINWORD")
            For Each ProcessInfo In WordProcesses
                lhtWinProcesses = New Hashtable
                lhtWinProcesses.Item("ProcessID") = ProcessInfo.Id
                parrWinProcesses.Add(lhtWinProcesses)
            Next
        Catch ex As Exception
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in CountWinProcesses in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' Kiil the newly  word Process 
    ''' </summary>
    ''' <param name="parrWinProcesses"></param>
    ''' <remarks></remarks>
    '''
    Public Sub KillWinProcesses(ByVal parrWinProcesses As ArrayList)
        Dim WordProcesses() As Process
        Try
            WordProcesses = Process.GetProcessesByName("WINWORD")
            Dim lintWinProcessCount As Integer = WordProcesses.Length
            Dim lintCounter As Integer = 0
            While lintCounter < lintWinProcessCount
                If parrWinProcesses.Count = 0 Then
                    WordProcesses(lintCounter).Kill()
                    lintCounter += 1
                    Continue While
                End If
                Dim lblnIsExist As Boolean = False
                For Each lhtWinProcess As Hashtable In parrWinProcesses
                    If WordProcesses(lintCounter).Id = lhtWinProcess.Item("ProcessID") Then
                        lblnIsExist = True
                        lintCounter += 1
                        Continue While
                    End If
                    If lblnIsExist = False Then
                        WordProcesses(lintCounter).Kill()
                        lintCounter += 1
                        Continue While
                    End If
                Next
                lintCounter += 1
            End While
        Catch ex As Exception
            'MessageBox.Show(ex.Message)
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in KillWinProcesses in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
        End Try

    End Sub

    ''' <summary>
    ''' AutoSize the columns Of grid
    ''' </summary>
    ''' <param name="grdExcel"></param>
    ''' <remarks></remarks>

    Public Sub FormatGrid(ByRef grdExcel As UltraGrid)
        Dim GridCol As UltraGridColumn
        Try
            If (grdExcel.DisplayLayout Is Nothing) Then Exit Sub
            grdExcel.DisplayLayout.Bands(0).Override.ColumnAutoSizeMode = ColumnAutoSizeMode.AllRowsInBand
            grdExcel.DisplayLayout.Bands(0).Override.AllowRowLayoutCellSpanSizing = Infragistics.Win.Layout.GridBagLayoutAllowSpanSizing.None
            grdExcel.DisplayLayout.Bands(0).Override.CellMultiLine = Infragistics.Win.DefaultableBoolean.False
            grdExcel.DisplayLayout.Bands(0).Override.DefaultColWidth = 0

            Dim rowCount As Integer = grdExcel.Rows.Count
            '**************************************
            'Added by Pankaj Garg
            If (rowCount > 0) Then
                '**********************************
                For Each GridCol In grdExcel.DisplayLayout.Bands(0).Columns
                    '  Application.DoEvents()
                    GridCol.PerformAutoResize(rowCount)
                    'GridCol.Format = "AutoFit"
                Next
            End If


        Catch ex As Exception
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in FormatGrid in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
        Finally
            GridCol = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' To count the WinProcesses running at the moment
    ''' </summary>
    ''' <param name="parrRunningWinProcesses">List of Already Running Win Processes</param>
    ''' <param name="parrNewWinProcesses">List of New Win Processes created by the tool</param>
    ''' <remarks></remarks>
    Public Sub CountRunningWinProcesses(ByRef parrRunningWinProcesses As ArrayList, ByRef parrNewWinProcesses As ArrayList, ByVal pblnIsAlreadyRunning As Boolean)
        Dim WordProcesses() As Process
        Dim ProcessInfo As Diagnostics.Process
        Dim lhtWinProcesses As Hashtable
        Dim lintProcessCounter As Integer = 0
        Try
            WordProcesses = Process.GetProcessesByName("WINWORD")
            If pblnIsAlreadyRunning Then
                For Each ProcessInfo In WordProcesses
                    lintProcessCounter = 0
                    While lintProcessCounter < parrNewWinProcesses.Count
                        If CType(parrNewWinProcesses(lintProcessCounter), Hashtable).Item("ProcessID") = ProcessInfo.Id Then
                            lintProcessCounter += 1
                            Continue For
                        End If
                        lintProcessCounter += 1
                    End While

                    lintProcessCounter = 0
                    While lintProcessCounter < parrRunningWinProcesses.Count
                        If CType(parrRunningWinProcesses(lintProcessCounter), Hashtable).Item("ProcessID") = ProcessInfo.Id Then
                            Continue For
                        End If
                        lintProcessCounter += 1
                    End While

                    lhtWinProcesses = New Hashtable
                    lhtWinProcesses.Item("ProcessID") = ProcessInfo.Id
                    parrRunningWinProcesses.Add(lhtWinProcesses)
                Next
            Else
                For Each ProcessInfo In WordProcesses
                    lintProcessCounter = 0
                    While lintProcessCounter < parrRunningWinProcesses.Count
                        If CType(parrRunningWinProcesses(lintProcessCounter), Hashtable).Item("ProcessID") = ProcessInfo.Id Then
                            Continue For
                        End If
                        lintProcessCounter += 1
                    End While
                    lintProcessCounter = 0
                    While lintProcessCounter < parrNewWinProcesses.Count
                        If CType(parrNewWinProcesses(lintProcessCounter), Hashtable).Item("ProcessID") = ProcessInfo.Id Then
                            Continue For
                        End If
                        lintProcessCounter += 1
                    End While
                    lhtWinProcesses = New Hashtable
                    lhtWinProcesses.Item("ProcessID") = ProcessInfo.Id
                    parrNewWinProcesses.Add(lhtWinProcesses)
                Next
            End If

        Catch ex As Exception
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in CountRunningWinProcesses in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
        Finally
            WordProcesses = Nothing
            lhtWinProcesses = Nothing
            lintProcessCounter = Nothing
        End Try
    End Sub

    Public Function NewCheckNothingDataTable(ByVal dt As DataTable) As Boolean
        Try
            If dt Is Nothing Then Return True
            If dt Is DBNull.Value Then Return True
            Return False
        Catch ex As Exception
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in NewCheckNothingDataTable in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
            Throw ex
        End Try
    End Function

    Public Function NewCheckEmptyDataTable(ByVal dt As DataTable) As Boolean

        Try
            If dt Is Nothing Then Return True
            If dt Is DBNull.Value Then Return True
            If dt.Rows.Count = 0 Then Return True
            Return False
        Catch ex As Exception
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in NewCheckEmptyDataTable in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
            Throw ex
        End Try

    End Function

    Public Sub GetSortedColumnName(ByRef pstrSortedCol As String, ByRef psiGridsSortIndicator As SortIndicator, ByVal pGrid As UltraGrid)
        Try
            If pGrid.DataSource Is Nothing Then Exit Sub
            If pGrid.Rows.Band.SortedColumns.Count > 0 Then
                pstrSortedCol = pGrid.Rows.Band.SortedColumns(0).Key
                psiGridsSortIndicator = pGrid.Rows.Band.SortedColumns(0).SortIndicator
            End If
        Catch ex As Exception
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in GetSortedColumnName in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
        End Try

    End Sub

    Public Sub SetSortedColumnName(ByRef pstrSortedCol As String, ByRef psiGridsSortIndicator As SortIndicator, ByVal pGrid As UltraGrid)
        Try
            If pGrid.DataSource Is Nothing Then Exit Sub
            If pGrid.Rows.Band.Columns.Exists(pstrSortedCol) Then
                pGrid.Rows.Band.Columns(pstrSortedCol).SortIndicator = psiGridsSortIndicator
                If pGrid.Rows IsNot Nothing AndAlso pGrid.Rows.Count > 0 Then
                    pGrid.Rows(0).Selected = True
                    pGrid.Rows(0).Activate()
                End If
            End If
        Catch ex As Exception
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in SetSortedColumnName in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
        End Try

    End Sub

    Public Sub vFormatGrid(ByRef grdExcel As UltraGrid)
        Dim col As UltraGridColumn
        Try
            grdExcel.DisplayLayout.Bands(0).Override.ColumnAutoSizeMode = ColumnAutoSizeMode.AllRowsInBand
            grdExcel.DisplayLayout.Bands(0).Override.AllowRowLayoutCellSpanSizing = Infragistics.Win.Layout.GridBagLayoutAllowSpanSizing.None
            grdExcel.DisplayLayout.Bands(0).Override.CellMultiLine = Infragistics.Win.DefaultableBoolean.False
            'grdExcel.DisplayLayout.Bands(0).Override.CellDisplayStyle = CellDisplayStyle.PlainText
            grdExcel.DisplayLayout.Bands(0).Override.DefaultColWidth = 0
            grdExcel.DisplayLayout.Bands(0).Override.AllowColSizing = AllowColSizing.None


            For Each col In grdExcel.DisplayLayout.Bands(0).Columns
                If col.Hidden = False Then Continue For
                Dim rowCount As Integer = grdExcel.Rows.Count
                Dim calculatedColumnWidth As Integer = col.CalculateAutoResizeWidth(rowCount, True)
                col.MaxLength = calculatedColumnWidth
                col.Width = calculatedColumnWidth
                col.PerformAutoResize(rowCount)
                col.RowLayoutColumnInfo.WeightX = 0
                col.ProportionalResize = True
                col.Format = "AutoFit"
            Next
            ' Dim str As String = grdExcel.DisplayLayout.Bands(0).Override.CellPadding.ToString()
        Catch ex As Exception
            'MessageBox.Show(ex.Message)
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in vFormatGrid in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
        Finally
            col = Nothing
        End Try

    End Sub

    Public Sub SetSortedColumnNameWithoutIndicatorTo0(ByRef pstrSortedCol As String, ByRef psiGridsSortIndicator As SortIndicator, ByVal pGrid As UltraGrid)
        Try
            If pGrid.DataSource Is Nothing Then Exit Sub
            If pGrid.Rows.Band.Columns.Exists(pstrSortedCol) Then
                pGrid.Rows.Band.Columns(pstrSortedCol).SortIndicator = psiGridsSortIndicator
            End If
        Catch ex As Exception
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in SetSortedColumnNameWithoutIndicatorTo0 in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
        End Try

    End Sub

    ''' <summary>
    ''' Kiil the newly  word Process 
    ''' </summary>
    ''' <param name="parrNewWinProcesses"></param>
    ''' <remarks></remarks>
    '''

    Public Sub KillNewWinProcesses(ByVal parrNewWinProcesses As ArrayList)
        Dim WordProcesses() As Process
        Dim ProcessInfo As Diagnostics.Process
        WordProcesses = Process.GetProcessesByName("WINWORD")
        Dim lintProcessCounter As Integer
        Try
            For Each ProcessInfo In WordProcesses
                lintProcessCounter = 0
                While lintProcessCounter < parrNewWinProcesses.Count
                    If CType(parrNewWinProcesses(lintProcessCounter), Hashtable).Item("ProcessID") = ProcessInfo.Id Then
                        Process.GetProcessById(CType(parrNewWinProcesses(lintProcessCounter), Hashtable).Item("ProcessID")).Kill()
                        Continue For
                    Else
                        'MessageBox.Show("Process does not exist anymore.", mstrMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning)
                    End If
                    lintProcessCounter += 1
                End While
            Next

        Catch ex As Exception
            'MessageBox.Show(ex.Message)
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in KillNewWinProcesses in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
        End Try
    End Sub

#Region "Data Table"

    'Public Function FindActiveColumnIndex(ByVal ldtColumns As DataTable) As Integer
    '    For Each lrow As DataRow In ldtColumns.Rows
    '        If lrow.Item("Column Name") = "Fund Name" Then
    '            Return ldtColumns.Rows.IndexOf(lrow) + 1
    '        End If
    '    Next
    'End Function

#End Region


#End Region

#Region "Data Table and Dataset"

    ''' <summary>
    ''' checks the dataset is Empty 
    ''' </summary>
    ''' <param name="ds"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>

    Public Function CheckEmptyDataSet(ByVal ds As DataSet) As Boolean

        Try
            If ds Is Nothing Then Return True
            If ds Is DBNull.Value Then Return True
            If ds.Tables.Count = 0 Then Return True
            Return False
        Catch ex As Exception
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in CheckEmptyDataSet in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
            Throw ex
        End Try

    End Function

    ''' <summary>
    ''' checks the datatable 
    ''' </summary>
    ''' <param name="dtDataTable"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>

    Public Function CheckNothingDataTable(ByVal dtDataTable As DataTable) As Boolean
        Try
            If dtDataTable Is Nothing Then Return False
            If dtDataTable Is DBNull.Value Then Return False
            Return True
        Catch ex As Exception
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in CheckNothingDataTable in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
            Throw ex
        End Try

    End Function

    Public Function CheckEmptyDataTable(ByVal dtDataTable As DataTable) As Boolean
        Try
            If dtDataTable Is Nothing Then Return True
            If dtDataTable Is DBNull.Value Then Return True
            If dtDataTable.Rows.Count = 0 Then Return True
            Return False
        Catch ex As Exception
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in CheckEmptyDataTable in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
            Throw ex
        End Try
    End Function

    ''' <summary>
    ''' Add a value in drop down at first place
    ''' </summary>
    ''' <param name="dataTable">Data Table to access</param>
    ''' <param name="idColumn">ID Column of row</param>
    ''' <param name="valueColumn">Text Column of row</param>
    ''' <param name="rowValue">ID Value of row</param>
    ''' <param name="rowText">Text Value of row</param>
    ''' <remarks></remarks>
    Public Function AddRowInDropDownAtFirst(ByRef dataTable As DataTable, ByVal idColumn As String, ByVal valueColumn As String, ByVal rowValue As Integer, ByVal rowText As String) As Boolean
        Try
            If CheckEmptyDataTable(dataTable) Then
                Return False
            End If
            Dim drDataRow As DataRow
            drDataRow = dataTable.NewRow
            drDataRow.Item(idColumn) = rowValue
            drDataRow.Item(valueColumn) = rowText
            dataTable.Rows.InsertAt(drDataRow, 0)
            Return True
        Catch ex As Exception
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in AddRowInDropDownAtFirst in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing

        End Try

    End Function

    ''' <summary>
    ''' Add a value in drop down at last place
    ''' </summary>
    ''' <param name="dataTable">Data Table to access</param>
    ''' <param name="idColumn">ID Column of row</param>
    ''' <param name="valueColumn">Text Column of row</param>
    ''' <param name="rowValue">ID Value of row</param>
    ''' <param name="rowText">Text Value of row</param>
    ''' <remarks></remarks>
    Public Function AddRowInDropDownAtLast(ByRef dataTable As DataTable, ByVal idColumn As String, ByVal valueColumn As String, ByVal rowValue As Integer, ByVal rowText As String) As Boolean
        Try
            If CheckEmptyDataTable(dataTable) Then
                Return False
            End If
            Dim drDataRow As DataRow
            drDataRow = dataTable.NewRow
            drDataRow.Item(idColumn) = rowValue
            drDataRow.Item(valueColumn) = rowText
            dataTable.Rows.Add(drDataRow)
            Return True
        Catch ex As Exception
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in AddRowInDropDownAtLast in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
        End Try

    End Function

    ''' <summary>
    ''' Find the index of a particular [Column Name] from datatable
    ''' </summary>
    ''' <param name="ldtTable">Data Table</param>
    ''' <param name="pstrColumnName">Column Name</param>
    ''' <returns>Column Index</returns>
    ''' <remarks></remarks>
    Public Function FindColumnIndex(ByVal ldtTable As DataTable, ByVal pstrColumnName As String) As Integer
        Try
            Dim lintColumnIndex As Integer = -1
            If ldtTable.Columns.Contains(pstrColumnName) Then
                lintColumnIndex = ldtTable.Columns(pstrColumnName).Ordinal
            End If
            'For Each lcol As DataColumn In ldtTable.Columns
            '    If lcol.ColumnName = pstrColumnName Then
            '        lintColumnIndex = ldtTable.Columns(lcol.ColumnName).Ordinal
            '        Exit For
            '    End If
            'Next
            Return lintColumnIndex
        Catch ex As Exception
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in FindColumnIndex in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
        End Try

    End Function

    ''' <summary>
    ''' Find the index of a particular [Row] from datatable
    ''' </summary>
    ''' <param name="ldtTable">Data Table</param>
    ''' <param name="pstrColumnName">Column Name</param>
    ''' <returns>Column Index</returns>
    ''' <remarks></remarks>
    Public Function FindRowIndex(ByVal ldtTable As DataTable, ByVal pstrColumnName As String, ByVal pstrValue As String) As Integer
        Try
            Dim lintRowIndex As Integer = -1
            For Each lRow As DataRow In ldtTable.Rows
                If lRow.Item(pstrColumnName).ToString = pstrValue Then
                    lintRowIndex = ldtTable.Rows.IndexOf(lRow)
                    Exit For
                End If
            Next
            Return lintRowIndex
        Catch ex As Exception
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in FindRowIndex in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
        End Try

    End Function

    Public Sub RemoveColumn(ByRef pdtTable As DataTable, ByVal pstrColName As String)
        Try
            If pdtTable.Columns.Contains(pstrColName) Then
                pdtTable.Columns.Remove(pstrColName)
            End If
        Catch ex As Exception
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in RemoveColumn in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
        End Try

    End Sub

    Public Sub SetReportAndSourceOrdinal(ByRef pdtTable As DataTable, ByVal pstrColName As String, ByVal pintColIndex As Integer)
        Try
            If pdtTable.Columns.Contains(pstrColName) Then
                pdtTable.Columns(pstrColName).SetOrdinal(pintColIndex)
            End If
        Catch ex As Exception
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in SetReportAndSourceOrdinal in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
        End Try

    End Sub

#End Region

#Region "Infragistics"

#Region "Ultra Grid"

    ''' <summary>
    ''' Check if DataSource has Rows and is not nothing
    ''' </summary>s
    ''' <param name="grdGrid">Grid to be checked</param>
    ''' <returns>Status (Yes/No)</returns>
    ''' <remarks></remarks>
    Public Function IsDataSourceWithRows(ByVal grdGrid As UltraGrid) As Boolean
        If grdGrid.DataSource IsNot Nothing Then
            If grdGrid.Rows.Count > 0 Then
                Return True
            Else
                Return False
            End If
        Else
            Return False
        End If
    End Function

    ''' <summary>
    ''' Check if a column exists in grid
    ''' </summary>
    ''' <param name="drUltraGridRow">Grid Row</param>
    ''' <param name="strColumnName">Column Name</param>
    ''' <returns>Status (Yes/No)</returns>
    ''' <remarks></remarks>
    Public Function IsColumnExistsInUltraGridRow(ByVal drUltraGridRow As UltraGridRow, ByVal strColumnName As String) As Boolean
        If drUltraGridRow.Band.Columns.Exists(strColumnName) Then
            Return True
        Else
            Return False
        End If
    End Function

    ''' <summary>
    ''' Check Active Cell, Active Row and Rows of Ultragrid for NOTHING
    ''' </summary>
    ''' <param name="grdUltraGrid"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>

    Public Function CheckNothingUltraGridActiveCell(ByVal grdUltraGrid As UltraGrid) As Boolean
        Try
            If grdUltraGrid.Rows Is Nothing Then Return False
            If grdUltraGrid.ActiveRow Is Nothing Then Return False
            If grdUltraGrid.ActiveRow.Cells Is Nothing Then Return False
            Return True
        Catch ex As Exception
            Throw ex
        End Try
    End Function

#End Region

#Region "UltraCombo"

    ''' <summary>
    ''' Check Data Source, Selected Row Ultracombo
    ''' </summary>
    ''' <param name="cmbUltracombo"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>

    Public Function CheckNothingUltraCombo(ByVal cmbUltracombo As UltraCombo) As Boolean
        Try
            If cmbUltracombo.DataSource Is Nothing Then Return False
            'If cmbUltracombo.SelectedRow Is Nothing Then Return False
            Return True
        Catch ex As Exception
            Throw ex
        End Try
    End Function

#End Region

#Region "List box"

    ''' <summary>
    ''' Check Data Source and Selected Item, Selected Row ListBox
    ''' </summary>
    ''' <param name="lstListBox"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>

    Public Function CheckSelectedItemInListBox(ByVal lstListBox As ListBox) As Boolean
        Try
            If lstListBox.DataSource Is Nothing Then Return False
            If lstListBox.SelectedItem Is Nothing Then Return False
            Return True
        Catch ex As Exception
            Throw ex
        End Try
    End Function

#End Region

#Region "Text Editor"

    ''' <summary>
    ''' This method set the control disable
    ''' </summary>
    ''' <param name="val"></param>
    ''' <param name="b"></param>
    ''' <remarks></remarks>
    Public Sub DisableAllButtons(ByVal val As Boolean, ByVal ParamArray b() As System.Windows.Forms.Control)
        Try
            For i As Integer = 0 To b.Length - 1
                If b(i).GetType.Name = "UltraTextEditor" Then
                    CType(b(i), Infragistics.Win.UltraWinEditors.UltraTextEditor).ReadOnly = Not val
                    b(i).Enabled = val
                    'CType(b(i), Infragistics.Win.UltraWinEditors.UltraTextEditor).t = Not val
                Else
                    b(i).Enabled = val
                End If
            Next
            'txtsearch.ReadOnly = Not val
        Catch ex As Exception
            Throw ex
        End Try

    End Sub
#End Region

#End Region

    ''' <summary>
    '''Sort data table 
    ''' </summary>
    ''' <param name="dt"></param>
    ''' <param name="str">Expression as string</param>
    ''' <remarks></remarks>
    <Extension()> _
    Public Sub Sort(ByRef dt As DataTable, ByVal str As String)
        Dim dv As DataView
        Try
            dv = New DataView(dt)
            dv.Sort = str
            dt = dv.ToTable()
        Catch ex As Exception
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in Sort in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
            Throw ex
        Finally
            dv = Nothing
        End Try
    End Sub

    Public Sub FormatGrid(ByRef grdExcel As UltraCombo)
        Dim GridCol As UltraGridColumn
        Try
            Dim rowCount As Integer = grdExcel.Rows.Count
            If grdExcel.Rows.Count = 0 Then
                Exit Sub
            End If
            grdExcel.DisplayLayout.Bands(0).Override.ColumnAutoSizeMode = ColumnAutoSizeMode.AllRowsInBand
            grdExcel.DisplayLayout.Bands(0).Override.AllowRowLayoutCellSpanSizing = Infragistics.Win.Layout.GridBagLayoutAllowSpanSizing.None
            grdExcel.DisplayLayout.Bands(0).Override.CellMultiLine = Infragistics.Win.DefaultableBoolean.False
            grdExcel.DisplayLayout.Bands(0).Override.DefaultColWidth = 0
            For Each GridCol In grdExcel.DisplayLayout.Bands(0).Columns
                GridCol.PerformAutoResize(rowCount)
                Application.DoEvents()
            Next
        Catch ex As Exception
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in FormatGrid in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
            Throw ex
        Finally
            GridCol = Nothing
        End Try
    End Sub

    Public Function GetDecimalValue(ByVal str As String) As String
        Try
            If Not str.Contains(".") And Not str = "" And Not str = "0" And Not str = "0.00" Then
                Return str + ".00"
            Else
                If str.Contains(".") And Not str = "0" And Not str = "0.00" Then
                    If str.IndexOf(".") = str.Length - 1 Then
                        Return str + "00"
                    Else
                        If str.IndexOf(".") = str.Length - 2 And Not str = "0" And Not str = "0.00" Then
                            Return str + "0"
                        Else
                            Return str
                        End If
                    End If
                End If
            End If
            Return ""
        Catch ex As Exception
            'Varun Thakur | 21/08/2009 
            ''Logging
            Dim MsgLog As New System.Text.StringBuilder
            MsgLog.Append("There is error in GetDecimalValue in mdlCommon")
            MsgLog.Append(Environment.NewLine)
            MsgLog.Append("Error Details:- ")
            MsgLog.Append(ex.ToString())

            MsgLog = Nothing
            Throw ex
        End Try
    End Function
    Public Sub DisposeControls(ByRef PName As Form)
        'Dim iCount As Integer
        'Dim _Parent As String = ""
        ''Dim _iChildCount As Integer
        ''Dim _iCCCount As Integer
        '_Parent = PName.Name
        'For iCount = 0 To PName.Controls.Count - 1
        '    If PName.Controls(PName.Controls.Count - 1).HasChildren Then
        '        PName.Controls(PName.Controls.Count - 1).
        '    End If
        '    PName.Controls(PName.Controls.Count - 1).Dispose()
        'Next
    End Sub

    Public Sub ShowMessage(ByVal message As String)
        MessageBox.Show(message, mstrMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub

#Region "Data Reader Read Only"
    Public Sub ChangeDataReaderDataSet(ByRef ChkTable As DataSet)
        For Each dttable As DataTable In ChkTable.Tables
            For Each lCol As DataColumn In dttable.Columns
                lCol.ReadOnly = False
                lCol.AllowDBNull = True
            Next
        Next
    End Sub
    Public Sub ChangeDataReaderDataTable(ByRef ChkTable As DataTable)
        For Each lCol As DataColumn In ChkTable.Columns
            lCol.ReadOnly = False
            lCol.AllowDBNull = True
        Next
    End Sub
#End Region


End Module
'End Namespace

